/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler.list;

import org.netbeans.swing.outline.RowModel;

import java.util.Enumeration;

public class ComponentRowModel implements RowModel {

    public Class getColumnClass(int col) {
        switch (col) {
        case 0: return String.class;
        case 1: return String.class;
        case 2: return Boolean.class;
        case 3: return Boolean.class;
        default:return null;
        }
    }

    public int getColumnCount() {
        return 4;
    }

    public String getColumnName(int col) {
        switch (col) {
            case 0: return "Element";
            case 1: return "Name";
            case 2: return "Hide";
            case 3: return "Lock";
            default: return null;
        }
    }

    public Object getValueFor(Object node, int col) {
        ListNode n = (ListNode)node;
        switch (col) {
        case 0: return n.getElement();
        case 1: return n.getName();
        case 2: return n.getHide();
        case 3: return n.getLock();
        default:return null;
        }
    }

    public boolean isCellEditable(Object node, int col) {
        return col > 0;
    }

    public void setValueFor(Object node, int col, Object val) {
        ListNode n = (ListNode)node;
        if (col == 2)      {n.setHide((Boolean)val);}
        else if (col == 3) {n.setLock((Boolean)val);}

        for (Enumeration children = n.children();
                           children.hasMoreElements(); ) {
                ListNode child = (ListNode) children.nextElement();
                setValueFor(child, col, val);
        }
    }
}
